﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

/// <summary>
///db_news 的摘要说明
/// </summary>
public class db_news
{
    SqlDBClass db;
	public db_news()
	{
        db = new SqlDBClass();
	}

    /// <summary>
    /// 增加新闻
    /// </summary>
    /// <param name="title"></param>
    /// <param name="content"></param>
    /// <param name="hit"></param>
    /// <returns></returns>
    public Boolean addNews(string title, string content, string isPic, string PicUrl)
    {
        string strsql = "insert into news(title,newscontent,newstime,isPic,PicUrl) values('" + title + "','" + content + "','" + DateTime.Now + "','" + isPic + "','" + PicUrl + "')";
        return db.execSqlNoQuery(strsql);
    }

    public Boolean delNews(string id)
    {
        string strsql = "delete from news where id=" + id;
        return db.execSqlNoQuery(strsql);
    }

    /// <summary>
    /// 更新新闻
    /// </summary>
    /// <param name="id"></param>
    /// <param name="title"></param>
    /// <param name="content"></param>
    /// <returns></returns>
    public Boolean updateNews(string id, string title, string content, string status, string isPic, string PicUrl)
    {
        string strsql = "update news set title='" + title + "',newscontent='" + content + "',status='" + status + "',isPic='" + isPic + "',PicUrl='" + PicUrl + "' where id=" + id;
        return db.execSqlNoQuery(strsql);
    }

    /// <summary>
    /// 查询所有新闻
    /// </summary>
    /// <returns></returns>
    public DataSet selectNewsALL() {
        string strsql = "select * from news order by id desc";
        return db.execSql(strsql);
    }

    public DataSet selectNewsALLOpen()
    {
        string strsql = "select * from news where status='0' order by id desc";
        return db.execSql(strsql);
    }

    public DataSet selectNewsALLTop_id(string top)
    {
        string strsql = "select top " + top + " * from news where status='0' order by id desc";
        return db.execSql(strsql);
    }

    public DataSet selectNewsALLTop_hit(string top)
    {
        string strsql = "select top " + top + " * from news where status='0' order by hit desc";
        return db.execSql(strsql);
    }
 //   string strsql = "SELECT news.*, newskind.kindName FROM news INNER JOIN newskind ON cint(news.kind) = cint(newskind.ID) where (news.kind = '" + kind + "') order by news.id desc";

    public DataSet selectNewsTop()
    {
        string strsql = "select top 1 ID from news where isPic='0' order by id desc";
        return db.execSql(strsql);
    }

    public DataSet selectNewsALLSlide()
    {
        string strsql = "select top 5 * from news where isPic='0' order by id desc";
        return db.execSql(strsql);
    }

    /// <summary>
    /// 查询单条新闻
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    public DataSet selectNewsONE(string id) {
        string strsql = "select * from news where id=" + id;
        return db.execSql(strsql);
    }

    public void newsHitadd(string id)
    {
        string strsql = "update news set hit=hit+1 where id=" + id;
        //db.execSql(strsql);
        db.execSqlNoQuery(strsql);
    }
}